home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / src.zoo / src / copyright.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-17  |  7.0 KB  |  246 lines

  1. /*                        Copyright (c) 1988 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: copyright.c,v 1.1 89/03/17 08:20:53 sau Exp $
  9.     $Source: /m1/mgr.new/src/RCS/copyright.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /m1/mgr.new/src/RCS/copyright.c,v $$Revision: 1.1 $";
  12.  
  13. /* flash a copyright notice at Mgr startup */
  14.  
  15. #include <sys/time.h> 
  16. #include <sys/signal.h>
  17. #include "bitmap.h"
  18. #include "copyright.h"
  19.  
  20. #define SSIZE    3        /* star size */
  21.  
  22. #define BG_COLOR        4    /* background color */
  23. #define LOGO_COLOR    2    
  24. #define CR_COLOR        5    /* copyright color */
  25.  
  26. static BITMAP *logo[] =
  27.     { &lb_0, &lb_1, &lb_2, &lb_3, &lb_4, &lb_5, &lb_6, &lb_7};
  28.  
  29. static struct timeval delay = {
  30.    (long) 0, (long) 120000
  31.    };
  32.  
  33. /* for "star trek" clip areas */
  34.  
  35. struct rect {
  36.     short x1,y1;
  37.     short x2,y2;
  38.     }c1,c2;
  39.  
  40. copyright(where)
  41. BITMAP *where;    /* where to blast the copyright */
  42.     {
  43.     BITMAP *notice = &cr;
  44.     int x = (BIT_WIDE(where)-BIT_WIDE(notice))/2;
  45.     int y = BIT_HIGH(where)/2;
  46.     int high = BIT_HIGH(logo[0]);
  47.     int wide = BIT_WIDE(logo[0]);
  48.     int mask = 1;        /* select mask (1 == kbd) */
  49.     int pid;                /* pid of "startrek" program */
  50.     register int i;
  51.     char c;
  52.  
  53.     c1.x1 = x - SSIZE;
  54.     c1.y1 = y - SSIZE;
  55.     c1.x2 = BIT_WIDE(notice) + x;
  56.     c1.y2 = BIT_HIGH(notice) + y;
  57.  
  58.     bit_blit(where,0,0,BIT_WIDE(where),
  59.             BIT_HIGH(where),BIT_SRC|GETCOLOR(BG_COLOR),0l,0,0);
  60.     bit_blit(where,x,y,BIT_WIDE(notice),BIT_HIGH(notice),
  61.             BIT_SRC^BIT_DST|GETCOLOR(BG_COLOR)^GETCOLOR(CR_COLOR),
  62.             notice,0,0);
  63.  
  64.     x = (BIT_WIDE(where)-wide)/2;
  65.     y = y - high - BIT_HIGH(notice);
  66.  
  67.     c2.x1 = x - SSIZE;
  68.     c2.y1 = y - SSIZE;
  69.     c2.x2 = wide + x;
  70.     c2.y2 = high + y;
  71.  
  72.     /* kick off stars */
  73.  
  74.     if ((pid=fork()) == 0) /* child */
  75.         fly(where,c1,c2);
  76.    else {
  77.         for(i=0;select(32,&mask,0,0,&delay) <= 0;i++,mask=1)
  78.             bit_blit(where,x,y,wide,high,
  79.             BIT_SRC|GETCOLOR(BG_COLOR),
  80.             logo[i%8],0,0);
  81.         read(0,&c,1);
  82.         kill(pid,SIGTERM);
  83.         while(wait(0)!=pid);
  84.         }
  85.     }
  86.  
  87. /* star trek effect */
  88.  
  89.  
  90. /*
  91.  * porter.c  Steve Hawley 4/3/87
  92.  * rehacked 5/18/1988 for extra speed.
  93.  * re-re hacked 6/20/88 for MGR (SAU)
  94.  * A demo to get stars inspired by Star Trek without
  95.  * using quickdraw, and by addressing the screen directly.
  96.  * this version is roughly 8 times faster than its quickdraw
  97.  * equivalent.
  98.  * In considering the bit drawing routines, remember that
  99.  * on the macintosh, a bit turned on is black, not white.
  100.  */
  101.  
  102. #define MAXZ 500 /* maximum z depth */
  103. #define NSTARS 256 /* maximum number of stars */
  104. #define SPEED    8        /* star speed */
  105. #define SCALE    (short)6    /* for rotator */
  106. #define COUNT    (short)3    /* for rotator */
  107. #define ON 1  /* plotting states */
  108. #define OFF 0
  109. #define Random() rand()
  110.  
  111. short maxv, maxh; /* display size */
  112. short hmaxv, hmaxh;    /* 1/2 display size */
  113.  
  114. struct st {
  115.         short x, y, z;
  116.     short color;
  117.         } stars[NSTARS]; /* our galaxy */
  118.  
  119. fly (where,clip1,clip2)
  120. BITMAP *where;
  121. struct rect clip1, clip2;        /* "holes" in galaxy */
  122. {
  123.         register short i;
  124.         register struct st *stp;
  125.  
  126.         init_all(where);     /* set up global variables */
  127.         for (i=0, stp = stars; i< NSTARS; i++, stp++) {
  128.                 /* initialize galaxy */
  129.                 do {
  130.                         stp->x = Random();
  131.                         stp->y = Random();
  132.                         stp->z = (Random() % MAXZ) + 1;
  133.                         stp->color = Random() % 23;
  134.                                 if (stp->color == BG_COLOR)
  135.                             stp->color++;
  136.             
  137.                 } while(project(where,stp->x, stp->y, stp->z, stp->color, ON,clip1,clip2)); /* on screen? */
  138.         }
  139.         while (1) { /* loop 'til button */
  140.                 i = NSTARS;
  141.                 stp = stars;
  142.                 do {
  143.                         project(where,stp->x, stp->y, stp->z, stp->color, OFF,clip1,clip2); /* turn star off*/
  144.                         if ((stp->z -= SPEED) <= 0) { /* star went past us */
  145.                                 stp->x = Random();
  146.                                 stp->y = Random();
  147.                                 stp->z = MAXZ;
  148.                         }
  149.                                 else {        /* rotate universe */
  150.                                     cordic(&stp->x,&stp->y,SCALE,COUNT);
  151.                                 }
  152.                         if (project(where,stp->x, stp->y, stp->z, stp->color, ON,clip1,clip2)) {
  153.                                 /* if projection is off screen, get a new position */
  154.                                 stp->x = Random();
  155.                                 stp->y = Random();
  156.                                 stp->z = MAXZ;
  157.                         }
  158.                 ++stp;
  159.                 } while(--i);
  160.         }
  161. }
  162.  
  163. project(where,x, y, z, col, state,clip1,clip2)
  164. register BITMAP *where;
  165. register short x, y, z;
  166. register int col;
  167. register short state;
  168. struct rect clip1, clip2;
  169. {
  170.         
  171.         /* one-point perspective projection */
  172.         /* the offsets (maxh/2) and maxv/2) ensure that the
  173.          * projection is screen centered
  174.          */
  175.         x = (x/z) + hmaxh;
  176.         y = (y/z) + hmaxv;
  177.         return(xplot(where,x, y, col, state,clip1,clip2));
  178.  
  179. }
  180.  
  181. init_all(where)
  182. register BITMAP *where;
  183. {
  184.    maxv = BIT_HIGH(where);
  185.    hmaxv = maxv>>1;
  186.    maxh = BIT_WIDE(where);
  187.    hmaxh = maxh>>1;
  188. }       
  189.  
  190. xplot(where,x, y, col, state,clip1,clip2)
  191. register BITMAP *where;
  192. register int x, y;
  193. register int col;
  194. int state;
  195. struct rect clip1, clip2;
  196. {
  197.         register short *line, b;
  198.         
  199.         /* are we on the screen? If not, let the caller know*/
  200.         if (x < 0 || x >= maxh || y < 0 || y >= maxv )
  201.             return(1);
  202.         if (!(x < clip1.x1 || x >= clip1.x2 || y < clip1.y1 || y >= clip1.y2 ))
  203.             return(0);
  204.         if (!(x < clip2.x1 || x >= clip2.x2 || y < clip2.y1 || y >= clip2.y2 ))
  205.             return(0);
  206.  
  207.         bit_blit(where,x,y,SSIZE,SSIZE, state ?
  208.         BIT_SRC^BIT_DST | GETCOLOR(col)^GETCOLOR(BG_COLOR) :
  209.         BIT_SRC | GETCOLOR(BG_COLOR),
  210.                  0l,0,0);
  211.         return(0);
  212. }
  213.  
  214. /* CORDIC rotator. Takes as args a point (x,y) and spins it */
  215. /* count steps counter-clockwise.                   1       */
  216. /*                                Rotates atan( --------- ) */
  217. /*                                                  scale   */
  218. /*                                                 2        */
  219. /* Therefore a scale of 5 is 1.79 degrees/step and          */
  220. /* a scale of 4 is 3.57 degrees/step                        */
  221.  
  222. cordic(x, y, scale, count)
  223. short *x, *y;
  224. register short scale, count;
  225.  
  226. {
  227.    register short tempx, tempy;
  228.  
  229.    tempx = *x;
  230.    tempy = *y;
  231.  
  232.    if (count > 0) /* positive count (counter-clockwise) */
  233.       for (; count; count--){
  234.          tempx -= (tempy >> scale);
  235.          tempy += (tempx >> scale); 
  236.       }
  237.    else          /* negative count (clockwise) */
  238.       for (; count; count++){
  239.          tempx += (tempy >> scale);
  240.          tempy += (tempx >> scale);
  241.       }
  242.  
  243.    *x = tempx;
  244.    *y = tempy;
  245. }
  246.